package top.blackr.folivora.common.pay.config;

import com.alipay.api.AlipayConfig;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.blackr.folivora.common.pay.constants.AliPayConstants;
import top.blackr.folivora.config.ApplicationProperties;

/**
 * @author BlackR
 */
@Configuration
@AllArgsConstructor
public class AliPayConfiguration {

    private final ApplicationProperties.AliPay aliProperties;

    @Bean
    public AlipayConfig alipayConfig() {
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(aliProperties.getServerUrl());
        alipayConfig.setAppId(aliProperties.getAppId());
        alipayConfig.setPrivateKey(aliProperties.getPrivateKey());
        alipayConfig.setAppCertPath(aliProperties.getLocalFileUrl() + AliPayConstants.APP_CERT_PATH);
        alipayConfig.setAlipayPublicCertPath(aliProperties.getLocalFileUrl() + AliPayConstants.ALIPAY_CERT_PATH);
        alipayConfig.setRootCertPath(aliProperties.getLocalFileUrl() + AliPayConstants.ALIPAY_ROOT_CERT_CRT);
        alipayConfig.setFormat("json");
        alipayConfig.setCharset("UTF8");
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }
}
